﻿<%
'注册插件
Call RegisterPlugin("DownloadCounter","ActivePlugin_DownloadCounter")

'挂口部分
Function ActivePlugin_DownloadCounter()

	Call Add_Filter_Plugin("Filter_Plugin_UEditor_Config","DownloadCounter_ExportUEConfig")
	Call Add_Action_Plugin("Action_Plugin_uEditor_FileUpload_End","DownloadCounter_uEditorUpload")

End Function

Call Add_Response_Plugin("Response_Plugin_Html_Js_Add","document.write(""<script type=\""text/javascript\"" src=\""" & BlogHost & "zb_users/PLUGIN/downloadcounter/times.asp\""></script>"");")

Function InstallPlugin_DownloadCounter()

End Function

Function UnInstallPlugin_DownloadCounter()

End Function

Function DownloadCounter_ExportUEConfig(m)
	'OpenConnect
	'Call GetConfigs()
	Dim j,k,tmp
	j=Split(m,"filePath:""")(0)
	k=Split(m,""",fileFieldName:")(1)
	tmp=BlogHost & "zb_users/plugin/downloadcounter/"
	m=j&"filePath:"""&tmp&""",fileFieldName:"&k
End Function

Function DownloadCounter_uEditorUpload

	If Instr(Request.ServerVariables("URL"),"imageUp.asp") Then Exit Function

	Dim objRS,id
	Set objRS=objConn.Execute("SELECT MAX([ul_ID]) FROM [blog_UpLoad]")
	If (Not objRS.bof) And (Not objRS.eof) Then id=objRS(0)
	Set objRS=Nothing

	strJSON="{'state':'"& objUpload.Error2Info(uEditor_ASPFormName) & "',"  '输出状态,SUCCESS代表成功
	strJSON=strJSON&"'url':'download.asp?id="&id&"',"  '输出上传后URL
	strJSON=strJSON&"'fileType':'."&objUpload.form(uEditor_ASPFormName&"_Ext")&"',"  '输出扩展名
	strJSON=strJSON&"'original':'"&objUpload.Form(uEditor_ASPFormName&"_Name")&"<span id=download_times"&id&"></span><script type=""text/javascript"">GetDownloadTimes("&id&")</script>'}"  '输出源文件

End Function

'重写这个函数，加上下载次数
Function ExportFileList(intPage)

	Dim i
	Dim objRS
	Dim strSQL
	Dim strPage
	Dim strOrder
	Dim intPageAll

	Call CheckParameter(intPage,"int",1)

	Response.Write "<div class=""divHeader"">" & ZC_MSG071 & "</div>"
	Response.Write "<div class=""SubMenu"">" & Response_Plugin_FileMng_SubMenu & "</div>"
	Response.Write "<div id=""divMain2"">"

	Response.Write "<form class=""search"" name=""edit"" id=""edit"" method=""post"" enctype=""multipart/form-data"" action=""../cmd.asp?act=FileUpload"">"
	Response.Write "<p>"& ZC_MSG108 &": </p>"
	Response.Write "<p><input type=""file"" id=""edtFileLoad"" name=""edtFileLoad"" size=""40"" />&nbsp;&nbsp;&nbsp;&nbsp;<input type=""submit"" class=""button"" value="""& ZC_MSG087 &""" name=""B1"" onclick='document.getElementById(""edit"").action=document.getElementById(""edit"").action+""&amp;filename=""+escape(edtFileLoad.value)' />&nbsp;&nbsp;<input class=""button"" type=""reset"" value="""& ZC_MSG088 &""" name=""B2"" />"
	Response.Write "&nbsp;<input type=""checkbox"" onclick='if(this.checked==true){document.getElementById(""edit"").action=document.getElementById(""edit"").action+""&amp;autoname=1"";}else{document.getElementById(""edit"").action=""../cmd.asp?act=FileUpload"";};SetCookie(""chkAutoFileName"",this.checked,365);' id=""chkAutoName""/><label for=""chkAutoName"">"& ZC_MSG131 &"</label></p></form>"

	Set objRS=Server.CreateObject("ADODB.Recordset")
	objRS.CursorType = adOpenKeyset
	objRS.LockType = adLockReadOnly
	objRS.ActiveConnection=objConn
	objRS.Source=""

	If CheckRights("Root")=False And CheckRights("FileAll")=False Then strSQL="WHERE [ul_AuthorID] = " & BlogUser.ID
	If Request.QueryString("order")="downnum" Then strOrder="[ul_DownNum] DESC,"

	Response.Write "<table border=""1"" width=""100%"" cellspacing=""0"" cellpadding=""0"" class=""tableBorder tableBorder-thcenter"">"
	Response.Write "<tr><th width='5%'>"& ZC_MSG076 &"</th><th width='10%'>"& ZC_MSG003 &"</th><th width=''>"& ZC_MSG001 &"</th><th width='12%'>"& ZC_MSG041 &"</th><th width='12%'>"& ZC_MSG075 &"</th><th width='8%'><a href='admin.asp?act=FileMng&amp;page=&amp;order=downnum' title='按下载量排序'>下载↓</a></th><th width='5%'></th><th width='5%'><a href='' onclick='BatchSelectAll();return false'>"& ZC_MSG229 &"</a></th></tr>"

	objRS.Open("SELECT * FROM [blog_UpLoad] " & strSQL & " ORDER BY " & strOrder & " [ul_PostTime] DESC")
	objRS.PageSize=ZC_MANAGE_COUNT
	If objRS.PageCount>0 Then objRS.AbsolutePage = intPage
	intPageAll=objRS.PageCount

	If (Not objRS.bof) And (Not objRS.eof) Then

		For i=1 to objRS.PageSize

			Response.Write "<tr><td>"&objRS("ul_ID")&"</td>"

			Call GetUsersbyUserIDList(objRS("ul_AuthorID"))
			Dim User
			For Each User in Users
				If IsObject(User) Then
					If User.ID=objRS("ul_AuthorID") Then
						Response.Write "<td>" & User.Name & "</td>"
					End If
				End If
			Next

			Response.Write "<td><a href='"& BlogHost & ZC_UPLOAD_DIRECTORY &"/"&Year(objRS("ul_PostTime")) & "/" & Month(objRS("ul_PostTime")) & "/"&Server.URLEncode(objRS("ul_FileName"))&"' target='_blank'>"&Year(objRS("ul_PostTime")) & "/" & Month(objRS("ul_PostTime")) & "/" &objRS("ul_FileName")&"</a></td>"

			Response.Write "<td>"&objRS("ul_FileSize")&"</td><td>"&FormatDateTime(objRS("ul_PostTime"), 2)&"</td><td>"&objRS("ul_DownNum")&"</td>"
			Response.Write "<td align=""center""><a href='../cmd.asp?act=FileDel&amp;id="&Server.URLEncode(objRS("ul_ID"))&"' onclick='return window.confirm("""& ZC_MSG058 &""");'><img src=""../image/admin/delete.png"" alt=""" & ZC_MSG063 & """ title=""" & ZC_MSG063 & """ width=""16"" /></a></td>"
			Response.Write "<td align=""center""><input type=""checkbox"" name=""edtDel"" id=""edtDel"&objRS("ul_ID")&""" value="""&objRS("ul_ID")&"""/></td>"
			Response.Write "</tr>"

			objRS.MoveNext
			If objRS.eof Then Exit For

		Next

	End If

	Response.Write "</table>"

	Response.Write "<form id=""frmBatch"" method=""post"" action=""../cmd.asp?act=FileDelBatch""><input type=""hidden"" id=""edtBatch"" name=""edtBatch"" value=""""/><input class=""button"" type=""submit"" onclick='BatchDeleteAll(""edtBatch"");if(document.getElementById(""edtBatch"").value){return window.confirm("""& ZC_MSG058 &""");}else{return false}' value="""&ZC_MSG228&""" id=""btnPost""/></form>" & vbCrlf

	If  intPageAll>1 Then
		strPage=ExportPageBar(intPage,intPageAll,ZC_PAGEBAR_COUNT,"admin.asp?act=FileMng&amp;page=")
		Response.Write "<hr/><p class=""pagebar"">" & ZC_MSG042 & ": " & strPage & "</p>"
	End If

	Response.Write "</div><script type=""text/javascript"">if(GetCookie(""chkAutoFileName"")==""true""){document.getElementById(""chkAutoName"").checked=true;document.getElementById(""edit"").action=document.getElementById(""edit"").action+String.fromCharCode(38)+""autoname=1"";};</script>"
	objRS.Close
	Set objRS=Nothing

	Response.Write "<script type=""text/javascript"">ActiveLeftMenu(""aFileMng"");</script>"

	ExportFileList=True

End Function
%>